home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_066 / foogol / foogol.doc < prev    next >
Text File  |  1992-05-06  |  4KB  |  167 lines

  1. fc.doc                        Last modified: 1986-12-15
  2.  
  3.  
  4.             The FOOGOL-IV compiler
  5.            relese notes and documentation
  6.                Per Lindberg, QZ
  7.                   The mad programmer strikes again!
  8.  
  9. NAME
  10.     fc - foogol compiler
  11.  
  12. SYNOPSIS
  13.     fc [ -d ] infile [ outfile ]
  14.  
  15. DESCRIPTION
  16.     fc compiles a foogol program into VAX/UNIX assembly language.
  17.     Default extentions are ".foo" for the source file and ".s"
  18.     for the compiled file. In other words, the resulting outfile
  19.     is is VAX/UNIX assembly language, and can be assebled and
  20.     linked with the vanilla UNIX as and ld programs.
  21.  
  22.     Options: (There is only one switch so far...)
  23.  
  24.     -d    Sets the debug option, which makes the compiler print
  25.         out internal diagnostics. Useful for debugging and
  26.         understanding the compiler.
  27.  
  28.     The foogol object code has to be linked with the RTS (Run-Time
  29.     system) and the C library in order to be able to do I/O.
  30.     Example:
  31.         fc foo
  32.         as foo.s -o foo.o
  33.         ld /lib/crt0.o rts.o foo.o -o foo -lc
  34.     Or (shorter):
  35.         fc foo
  36.         cc rts.o foo.s -o foo
  37.  
  38.     The RTS (Run-Time System) should be compiled before it is
  39.     linked with the foogol object code. It consists of just three
  40.     output functions written in C:
  41.  
  42.     PRS(s) char *s; { printf("%s",s); }
  43.  
  44.     PRN(i) int i;   { printf("%d",i); }
  45.  
  46.     PR()            { putchar('\n');  }
  47.  
  48.     The foogol language is basically a very small ALGOL. The
  49.     current syntactic elements are:
  50.  
  51.     PROGRAM ::=        begin
  52.                 [ DECLARATION ; ]
  53.                 STATEMENT [ ; STATEMENT ]...
  54.                 end
  55.  
  56.     DECLARATION    ::=    integer ID_SEQUENCE
  57.  
  58.     ID_SEQUENCE    ::=    IDENTIFIER [ , IDENTIFIER ]
  59.  
  60.     STATEMENT    ::=    IO_STATEMENT
  61.             !    WHILE_STATEMENT
  62.             !    COND_STATEMENT
  63.             !    BLOCK
  64.             !    ASSIGN_STATEMENT
  65.  
  66.     BLOCK        ::=        begin
  67.                 [ DECLARATION ]
  68.                 [ ; STATEMENT ]...
  69.                 end
  70.  
  71.     IO_STATEMENT    ::=    prints ( STRING )
  72.             !    printn ( EXPRESSION )
  73.             !    print
  74.  
  75.     COND_STATEMENT    ::=    if EXPRESSION then STATEMENT
  76.                 [ else STATEMENT ]
  77.  
  78.     WHILE_STATEMENT    ::=    while EXPRESSION do STATEMENT
  79.  
  80.     ASSIGN_STATEMENT::=    IDENTIFIER := EXPRESSION
  81.  
  82.     EXPRESSION    ::=    EXPR1 [ RHS ]
  83.  
  84.     RHS        ::=    = EXPR1
  85.             !    # EXPR1
  86.  
  87.     SIGNED_TERM    ::=    + TERM
  88.             !    - TERM
  89.  
  90.     TERM        ::=    PRIMARY [ * PRIMARY ]...
  91.  
  92.     PRIMARY        ::=    IDENTIFIER
  93.             !    NUMBER
  94.             !    ( EXPRESSION )
  95.  
  96.     EXPR1        ::=    TERM [ SIGNED_TERM ]...
  97.  
  98.     IDENTIFIER    ::=    <the usual thing, and no word reserved>
  99.  
  100.     NUMBER        ::=    <the usual thing, unsigned integers>
  101.  
  102.     STRING        ::=    <the usual thing>
  103.  
  104.     Example program:
  105.  
  106.     begin
  107.       integer n, div, sub, test, testcopy, found, max;
  108.       test := 2; max := 10; /* number of primes wanted */
  109.       while n # max do begin
  110.         div:= test-1; found:= 0;
  111.         while div-1 do begin
  112.           testcopy:= test; sub:= 0;
  113.           while testcopy do begin
  114.             sub:= sub+1; if sub = div then sub:= 0;
  115.             testcopy:= testcopy-1
  116.           end;
  117.           if sub = 0 then found:= 1;
  118.           div:= div-1
  119.         end;
  120.         if found = 0 then begin
  121.           n:= n+1;
  122.           printn(test); prints(" is prime number "); printn(n); print
  123.         end;
  124.         test:= test+1
  125.       end
  126.     end
  127.  
  128.     The syntax is highly flexible, which means it might easily be
  129.     changed due to some whim. The source code should be checked
  130.     for details and changes before bugs are reported.
  131.  
  132.     The compiler is written by Per Lindberg, and placed in the
  133.     public domain. The Hacker's Ethic applies. It is based on the
  134.     VALGOL I compiler published by G.A. Edgar in Dr. Dobb's
  135.     Journal May 1985. It was implemented for the purpouse of
  136.     demonstrating how a simple compiler works. Therefore, there
  137.     are no optimizations or other frills. You might want to add
  138.     things to it; go right ahead. Happy hacking!
  139.  
  140. FILES
  141.     fc.c    Source code for the foogol compiler
  142.     fc    The foogol compiler
  143.     rts.c    Source code for the Run-Time system
  144.     rts.o    The Run-Time system
  145.     fc.doc    This file
  146.     bar.foo    Your program...
  147.  
  148. SEE ALSO
  149.     as, ld, cc
  150.  
  151. BUGS
  152.     There are no scoping rules, all declared variables can be used
  153.     throughout the entire program. And although you can have local
  154.     declarations in blocks, these declarations are in fact global.
  155.     So you can't redeclare a variable.
  156.  
  157.     Because parsing is by simple recursive-descent and backtracking,
  158.     there is only one cheerful error message: "Syntax error". No
  159.     hints on missing or superflous semicolons or such hand-holding.
  160.     You're supposed to write correct programs in foogol, Buster!
  161.  
  162.     The output code is extremely naive, and very suitable for
  163.     code optimization exercises.
  164.  
  165.     Finally, please remember that this is just a 500-line toy
  166.     compiler, so don't expect too much of it.
  167.